package com.xnx3.wangmarket.plugin.innerAccount.controller.admin;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xnx3.j2ee.service.SqlService;
import com.xnx3.j2ee.service.SystemService;
import com.xnx3.j2ee.util.Page;
import com.xnx3.j2ee.util.Sql;
import com.xnx3.j2ee.vo.BaseVO;
import com.xnx3.wangmarket.admin.controller.BaseController;
import com.xnx3.wangmarket.admin.util.AliyunLog;
import com.xnx3.wangmarket.plugin.base.controller.BasePluginController;
import com.xnx3.wangmarket.plugin.innerAccount.entity.Department;
import com.xnx3.DateUtil;
import com.xnx3.j2ee.entity.System;

/**
 * 系统管理
 * @author 管雷鸣
 */
@Controller
@RequestMapping("/plugin/innerAccount/admin/system/")
public class SystemInnerAccountPluginController extends BasePluginController {

	@Resource
	private SqlService sqlService;
	@Resource
	private SystemService systemService;
	

	/**
	 * 更改云端模版是否使用
	 * @param value 值
	 */
	@RequestMapping(value="updateLoginSuccessLink${url.suffix}", method = RequestMethod.POST)
	@ResponseBody
	public BaseVO updateLoginSuccessLink(HttpServletRequest request,
			@RequestParam(value = "value", required = true) String value){
		if(!haveSuperAdminAuth()){
			return error("无权操作");
		}
		
		List<System> sysList = sqlService.findByProperty(System.class, "name", "PLUGIN_INNERACCOUNT_LOGINSUCCESS_LINK");
		System sys;
		if(sysList.size() == 0){
			sys = new System();
			sys.setName("PLUGIN_INNERACCOUNT_LOGINSUCCESS_LINK");
			sys.setLasttime(DateUtil.timeForUnix10());
			sys.setDescription("登陆成功之后跳转到的链接url地址。如系统内部为/plugin/innerAccount/admin/department/list.do，系统外部则是http...绝对路径");
		}else{
			sys = sysList.get(0);
		}
		sys.setValue(value);
		sqlService.save(sys);
		
		//刷新缓存
		systemService.refreshSystemCache();
		
	    AliyunLog.addActionLog(getSiteId(), "innerAccount插件更新登陆成功之后跳转到的url地址",sys.getValue());
	    return success();
	}
	
	
}